package com.jack.ffmpeg_simple02;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import androidx.annotation.NonNull;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

/**
 * @创建者 Jack
 * @创建时间 2025-07-12 12:40
 * @描述
 */
public class PlayView extends GLSurfaceView implements SurfaceHolder.Callback, GLSurfaceView.Renderer,Runnable{

    public PlayView(Context context, AttributeSet attrs) {
        super(context, attrs);

        //适配Android8.0及以上  无法正常渲染视频的问题
        setRenderer( this );
    }

    @Override
    public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {

    }

    @Override
    public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
        new Thread( this ).start();
    }

    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {

    }

    @Override
    public void onDrawFrame(GL10 gl10) {

    }

    @Override
    public void onSurfaceChanged(GL10 gl10, int i, int i1) {

    }

    @Override
    public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {

    }

    public native void PlayYuv(String url,Object surface);

    @Override
    public void run() {
        //注意：需要手动开启存储权限
        PlayYuv("/sdcard/out.yuv",getHolder().getSurface());
    }
}
